         
//  进度条引入设置如上面第一种描述一样
import router from '@/router/routers.js'
import store from '@/store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie

const whiteList = ['/login'];
	
router.beforeEach( async (to, from, next) => {
    NProgress.start()
    document.title = to.meta.title;
    // 获取用户token，用来判断当前用户是否登录
    const hasToken = getToken()
    if (hasToken) {
        if (to.path === '/login'|to.path === '/') {
            next({ path: '/main/home' })
        } else {
            next()
        }
    } else {
        if (whiteList.indexOf(to.path) !== -1) {
           next()
        } else {
            next(`/login?redirect=${to.path}`)
            // NProgress.done()
        }
    }
})


router.afterEach(() => {
    NProgress.done()
})
/* import store from '@/store'


export default function checkPermission(value) {
  if (value && value instanceof Array && value.length > 0) {
    const roles = store.getters && store.getters.roles
    const permissionRoles = value

    const hasPermission = roles.some(role => {
      return permissionRoles.includes(role)
    })

    if (!hasPermission) {
      return false
    }
    return true
  } else {
    console.error(`need roles! Like v-permission="['admin','editor']"`)
    return false
  }
}
 */